# conding = utf-8
import time

from selenium.webdriver import ActionChains, Keys

from pages.page import Page
from pages.lyz.finance.payment import left_menu_sys, left_menu, btn_unfold, id_send, time_began, time_left, \
    time_began_open, time_finishes_open, find_btn, find_reset, find_expected, unit, unit_open, operator, operator_open, \
    finance, finance_open, account, account_open, state, state_open, remark, add_btn, \
    add_select_btn, add_select_id, add_select_name, add_select_began, add_select_year, add_select_began_date, \
    add_select_finishes_date, add_select_button, add_select_expected, add_client, add_chosen,add_select_identify, add_finance, \
    add_amount, add_remark, get_tishi, add_button, add_cancel, update,update_beginning, beginning_btn, delete, delete_btn, delete_expected, batch, batch_btn, pl_delete, \
    pl_audit, pl_anti_audit, queding


class PaymentPages(Page):
    def open_sales_order(self):
        '''
        打开管理员UI，如果已经打开则不会执行单击动作
        :return:
        '''
        if self.display(left_menu) is False:  # 如果是隐藏状态则单击
            self.click(left_menu_sys)
        self.click(left_menu)

    def btn_unfold(self):
        self.click(btn_unfold)

    def id_send(self, value):
        self.send_keys(id_send, value)

    def time_began(self):
        self.click(time_began)

    def time_left(self):
        self.click(time_left)

    def time_began_open(self):
        self.click(time_began_open)

    def time_finishes_open(self):
        self.click(time_finishes_open)

    def search_result_text(self, value):
        if value == 'FK00000001079':
            return self.text(find_expected)

    def unit(self):
        self.click(unit)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def operator(self):
        self.click(operator)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.UP)
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def finance(self):
        self.click(finance)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def account(self):
        self.click(account)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def state(self):
        self.click(state)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.DOWN)
        actions.send_keys(Keys.DOWN)
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def find_btn(self):
        self.click(find_btn)

    def find_reset(self):
        self.click(find_reset)

    def remark(self, value):
        self.send_keys(remark, value)

    def add_btn(self):
        self.click(add_btn)

    def add_select_btn(self):
        self.click(add_select_btn)

    def add_client(self):
        self.click(add_client)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        time.sleep(1)
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def add_select_id(self, value):
        self.send_keys(add_select_id, value)

    def add_select_name(self, value):
        self.send_keys(add_select_name, value)

    def add_select_began(self):
        self.click(add_select_began)

    def add_select_year(self):
        self.click(add_select_year)
        time.sleep(1)
        self.click(add_select_year)
        time.sleep(1)
        self.click(add_select_year)
        time.sleep(1)
        self.click(add_select_year)

    def add_select_began_date(self):
        self.click(add_select_began_date)

    def add_select_finishes_date(self):
        self.click(add_select_finishes_date)

    def add_select_button(self):
        self.click(add_select_button)

    def add_select_expected(self, value):
        if value == 'CGRK00000000651':
            return self.text(add_select_expected)

    def add_chosen(self):
        self.click(add_chosen)

    def add_select_identify(self):
        self.click(add_select_identify)

    def add_finance(self):
        self.click(add_finance)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def add_amount(self,value):
        self.send_keys(add_amount, value)

    def add_remark(self, value):
        self.send_keys(add_remark, value)

    def get_tishi(self):
        return self.is_exists(get_tishi)

    def some_method(self):
        # 判断元素是否存在并返回 True 或 False
        if self.is_exists(get_tishi):  # 调用 is_exists 方法，传入 get_tishi 定位器
            return True
        else:
            return False

    def add_button(self):
        self.click(add_button)

    def add_cancel(self):
        self.click(add_cancel)

    def update(self):
        self.click(update)

    def update_beginning(self):
        self.click(update_beginning)

    def beginning_btn(self):
        self.click(beginning_btn)

    def delete(self):
        self.click(delete)

    def delete_btn(self):
        self.click(delete_btn)

    def delete_expected(self):
        return self.text(delete_expected)

    def batch(self):
        self.click(batch)

    def batch_btn(self):
        self.click(batch_btn)

    def pl_audit(self):
        self.click(pl_audit)

    def pl_delete(self):
        self.click(pl_delete)

    def pl_anti_audit(self):
        self.click(pl_anti_audit)

    def queding(self):
        self.click(queding)
